package com.czie.myapplication;

import android.app.IntentService;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

import androidx.annotation.Nullable;

public class ReceiveService extends IntentService {
    public ReceiveService() {
        super("receiveService");
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        throw new UnsupportedOperationException("Not yet implemented");
    }

    int isTimeStart = 0;

    @Override
    protected void onHandleIntent(@Nullable Intent intent) {
        // ReceiveService的执行方法，将要在服务中实现的功能，在这里进行执行
        Log.d("receiveService", "onHandleIntent is started");
        int i = 0;
        while (true) {
            if (isTimeStart == 0) {
                i++;
            } else if (isTimeStart == 1) {

            } else {
            }
            // 添加广播，进行发送
            BroadcastSender sender = new BroadcastSender();
            sender.send("nameForI", i);
            Log.e("onHandleIntent", " i = " + i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}